/*
 * =========================================================
 * 文件上传
 * 
*/

import errorLog from './errorLog'
import {localStorage} from '../common/util'

const csrfConfig = {
    'Accept':'application/json',
    'content-type':'multipart/form-data'
};

export default (url = '', file, name, data = {}) => {
    try {
        return new Promise((resolve, reject) => {
            const uploadTask = uni.uploadFile({
                header: csrfConfig,
                url: url, 
                filePath: file,
                name: name,
                formData: data,
                success: (requestObj) => {      
                            resolve(requestObj);                  
                },
                fail: (error) => {
                    errorLog({type:"error",data:error}).then((res)=>{
                        reject(res);
                    });
                }
            });
			uploadTask.onProgressUpdate(function (res) {
				 /* uni.showLoading({
				  	title:'图片上传中'+res.progress+'%',
					mask: true
				  }); */
			     });
        })
    } catch (error) {
        throw new Error(error)
    }
}

















